package com.ruoyi.web.controller.mall;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.domain.MallGoodsNorm;
import com.ruoyi.mall.service.MallGoodsNormService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品规格Controller
 *
 * @author ruoyi
 * @date 2024-01-11
 */
@Api(tags = "商品规格")
@RestController
@RequestMapping("/mall/norm")
public class MallGoodsNormController extends BaseController {
    @Autowired
    private MallGoodsNormService mallGoodsNormService;

    /**
     * 查询商品规格列表
     */
    @ApiOperation("查询商品规格列表")
    @PreAuthorize("@ss.hasPermi('mall:norm:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody MallGoodsNorm mallGoodsNorm) {
        startPage();
        List<MallGoodsNorm> list = mallGoodsNormService.selectMallGoodsNormList(mallGoodsNorm);
        return getDataTable(list);
    }

    /**
     * 获取商品规格详细信息
     */
    @ApiOperation("获取商品规格详细信息")
    @PreAuthorize("@ss.hasPermi('mall:norm:query')")
    @PostMapping(value = "getInfo/{normId}")
    public AjaxResult getInfo(@PathVariable("normId") Long normId) {
        return success(mallGoodsNormService.selectMallGoodsNormByNormId(normId));
    }

    /**
     * 保存商品规格
     */
    @ApiOperation("保存商品规格")
    @PreAuthorize("@ss.hasPermi('mall:norm:save')")
    @Log(title = "商品规格", businessType = BusinessType.SAVE)
    @PostMapping("save")
    public AjaxResult save(@RequestBody List<MallGoodsNorm> normList) {
        return toAjax(mallGoodsNormService.saveGoodsNorm(normList));
    }

    /**
     * 删除商品规格
     */
    @ApiOperation("删除商品规格")
    @PreAuthorize("@ss.hasPermi('mall:norm:remove')")
    @Log(title = "商品规格", businessType = BusinessType.DELETE)
    @PostMapping("remove/{normIds}")
    public AjaxResult remove(@PathVariable Long[] normIds) {
        return toAjax(mallGoodsNormService.deleteMallGoodsNormByNormIds(normIds));
    }
}
